//
//  TBRChooseCouponListC.m
//  TBRentClient
//
//  Created by tonbright on 2018/4/27.
//  Copyright © 2018年 tonbright. All rights reserved.
//

#import "TBRChooseCouponListC.h"
#import "TBRChooseCoupListHeadCell.h"
#import "TBRChooseCoupListCell.h"

@interface TBRChooseCouponListC ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView      *tableView;
@end

@implementation TBRChooseCouponListC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)setupUI {
    //设置导航条
    [self setupNavItem];
    
    //添加tableView
    [self setupTableView];
}

- (void)setupNavItem {
    [self ISG_NavigationBarDefaultBackButtonAndNavigationTitle:@"选择优惠券"];
}

- (void)setupTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.bottom.offset(0);
    }];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [UIView new];
    [self.tableView registerNib:[UINib nibWithNibName:@"TBRChooseCoupListHeadCell" bundle:nil] forCellReuseIdentifier:@"TBRChooseCoupListHeadCellId"];
    [self.tableView registerNib:[UINib nibWithNibName:@"TBRChooseCoupListCell" bundle:nil] forCellReuseIdentifier:@"TBRChooseCoupListCellId"];
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, -45, 0, 0)];
    }
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    self.tableView.sectionHeaderHeight = 0;
    self.tableView.sectionFooterHeight = 0;
}

#pragma mark - 返回组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

#pragma mark - 返回行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return section == 0 ? 1 : 3;
}

#pragma mark - 返回每行内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        TBRChooseCoupListHeadCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TBRChooseCoupListHeadCellId" forIndexPath:indexPath];
        return cell;
    }
    
    //自定义cell
    TBRChooseCoupListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TBRChooseCoupListCellId" forIndexPath:indexPath];
    //    cell.goodsModel = self.allGoodsArray[indexPath.row];
    //设置数据
    //返回
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return indexPath.section == 0 ? 44 : 118;
}



- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.1;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [UIView new];
    view.frame = CGRectMake(0, 0, Width, 0.1);
    return view;
}



- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end
